import struct
import zlib
import hashlib
import base64,binascii,zlib
import os,random

base = [str(x) for x in range(10)] + [ chr(x) for x in range(ord('A'),ord('A')+6)]

def abc(str):
    return sha.new(str).hexdigest()

def bin2dec(string_num):
    return str(int(string_num, 2))

def hex2dec(string_num):
    return str(int(string_num.upper(), 16))

def dec2bin(string_num):
    num = int(string_num)
    mid = []
    while True:
        #print "dec2"
        if num == 0: break
        num,rem = divmod(num, 2)
        mid.append(base[rem])
    #print out
    return ''.join([str(x) for x in mid[::-1]])

def dec2hex(string_num):
    num = int(string_num)
    mid = []
    while True:
        #print "dec2hex"
        if num == 0: break
        num,rem = divmod(num, 16)
        mid.append(base[rem])
    
    return ''.join([str(x) for x in mid[::-1]])

def hex2bin(string_num):
    return dec2bin(hex2dec(string_num.upper()))

def bin2hex(string_num):
    return dec2hex(bin2dec(string_num))

def reverse(string):
    return string[::-1]

def read_key():
    os.system('cat flag')

def gb2312(string):
    return string.decode('gb2312')


def zha1(dat,bs):
    def crc(d):
        return (~zlib.crc32(d)) & 0xFFFFFFFF
    
    ff = struct.unpack("I", dat[0:4])[0]
    
    tdat = struct.pack("I", 0xFFFFFFFF & (ff ^ (bs * 0x1337D00D)))#bs --> block size from 0 - 15000
    tdat += dat[4:]
    top = struct.pack("I", crc(tdat)^bs)
    
    print top.encode("hex"), hashlib.md5(tdat).hexdigest()


def xor(a,b):
	return "".join(map(lambda c: chr((ord(c[0])^ord(c[1]))), zip(a,b)))


def crc(dat):
    return ~zlib.crc32(dat, 0xFFFFFFFF)


#print xor(zlib.crc32("\x00\xBB"),zlib.crc32("\xAA\x00")) ,crc("\xAA\xBB")

#print xor("0x1d6a78fb","0x1531469c")
#print hex(zlib.crc32("\xAA\xBB"))


b1="123456"
c1="123451"

#print zlib.crc32(c1)
#print zlib.crc32(b1)

a= crc(b1+6*"\x00")
b= crc(6*"\x00"+c1)
print a^b
#print zlib.crc32(b1+6*"\x00")^zlib.crc32(6*"\x00"+c1)
c= crc(b1+c1)
print c





'''
    LHC: Ludicrous Hash Collider
    An hour of this challenge binary working costs CTF organizers $0.000001. We don't want to waste our money, so you're required to spend some cycles too.
    
    As the proof of work, give me two different blocks of length 364 with same ZHA1 hash.
    Send block 0
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    Send block 1
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    Got different hashes: 57e8153bd8a10c419bd2ffc7dc1526893be7ef9e and b10946d32bb0f44695c8aa36e8e6b0eff18c84b3
    
    LHC: Ludicrous Hash Collider
    An hour of this challenge binary working costs CTF organizers $0.000001. We don't want to waste our money, so you're required to spend some cycles too.
    
    As the proof of work, give me two different blocks of length 330 with same ZHA1 hash.
    Send block 0
    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    Send block 1
    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    Got different hashes: f2f12fdbed9fbded68de1cab5b8e44a9e6d1fb87 and cc75719ff7506736e1094d3dc66513eaa1e70ab9
    
    As the proof of work, give me two different blocks of length 477 with same ZHA1 hash.
    Send block 0
    ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
    Send block 1
    sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
    Got different hashes: a0049280c06f9374f7894636c196bbdf42ccfece and 4a8296b91e31c7880d61e684cfe2c4984ec56d3d
'''